import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { MCPProvider } from './contexts/MCPContext.tsx';

// 实现callTool函数来调用MCP工具
const callTool = async (toolName, args) => {
  try {
    // 这里需要实现实际的MCP工具调用逻辑
    // 暂时使用模拟数据
    console.log(`Calling MCP tool: ${toolName}`, args);
    
    // 模拟API调用延迟
    await new Promise(resolve => setTimeout(resolve, 500));
    
    // 返回模拟数据
    if (toolName === 'get_news') {
      return [
        {
          id: 1,
          title: '示例新闻标题',
          summary: '这是示例新闻的摘要内容...',
          date: '2023-06-15'
        }
      ];
    } else if (toolName === 'get_policies') {
      return [
        {
          id: 1,
          title: '示例政策标题',
          department: '财政部',
          date: '2023-06-10',
          content: '这是示例政策的内容...'
        }
      ];
    }
    
    throw new Error(`Unknown tool: ${toolName}`);
  } catch (error) {
    console.error('MCP tool call failed:', error);
    throw error;
  }
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <MCPProvider callTool={callTool}>
      <App />
    </MCPProvider>
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();